<?php if (!defined('THINK_PATH')) exit(); /*a:4:{s:98:"D:\PHPStudy\PHPTutorial\WWW\HM\pdingzone\public/../addons/hmls_assets\view\admin\user_log\all.html";i:1544590057;s:48:"../application/core/view/common/pc/bean/all.html";i:1544678555;s:46:"../application/core/view/common/pc/header.html";i:1544678555;s:46:"../application/core/view/common/pc/footer.html";i:1544678555;}*/ ?>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>资产申领请求列表 - <?php echo $siteConfig['siteName']; ?></title>
    <meta name="keywords" content="<?php echo $siteConfig['siteKeyword']; ?>"/>
    <meta name="description" content="<?php echo $siteConfig['siteDesc']; ?>"/>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link href="<?php echo $siteConfig['favicon']; ?>" type="image/x-icon" rel="shortcut icon"/>
    <link rel="stylesheet" href="/static/layui/2.4.3/src/css/layui.css?v=20181010_1" media="all">
    <link rel="stylesheet" href="//at.alicdn.com/t/font_731151_u29ky3lpahq.css?v=20181010_1" media="all">
    <link rel="stylesheet" href="/static/css/pc.css?v=20181010_1" media="all">
    <script src="/static/js/jquery.min.js?v=20181010_1" charset="utf-8"></script>
    <script src="/static/layui/2.4.3/src/layui.js?v=20181010_1" charset="utf-8"></script>
    <script src="/static/js/common.js?v=20181010_1" charset="utf-8"></script>
    <script src="/static/js/pc.js?v=20181010_1" charset="utf-8"></script>

    <?php if($siteConfig['theme']): ?>
    <link rel="stylesheet" href="/static/css/theme/<?php echo $siteConfig['theme']; ?>/pc.css?v=20181010_1" media="all">
    <?php endif;  if(\think\App::$debug){  ?>
    <!-- 调试窗口 -->
    <script src="/static/js/vconsole/vconsole.min.js?v=20181010_1" charset="utf-8"></script>
    <script>
        // 调试窗口初始化
        new VConsole();
    </script>
    <?php  }  ?>
</head>

<body class="layui-layout-body pc-body">


<script type="text/javascript" src="/static/js/date/date-zh-CN.js"></script>
<script>
    //config的设置是全局的
    layui.config({
        base: '/static/layui/mods' //假设这是你存放拓展模块的根目录
    }).extend({
        formSelects: '/formSelects/dist/formSelects-v4'
    });
</script>
<link rel="stylesheet" href="/static/layui/mods/formSelects/dist/formSelects-v4.css"/>

<!-- 样式 -->
<style>
    #table_container img.cell-img {
        cursor: pointer;
    }

    #table_container .layui-table tbody tr:hover,
    #table_container .layui-table-hover.layui-table[lay-even] tr:nth-child(even),
    #table_container .layui-table tbody tr:hover, .layui-table-hover {
        background: #b8b6b6 !important;
        color: #fff;
    }

    #table_container .layui-table-view .layui-table-page > div {
        float: right;
    }

    #table_container .layui-table-view .layui-table-page.layui-hide {
        display: initial !important;
    }

    #table_container .layui-table-tool .data_table_global_toolbar {
    }

    #table_container .layui-table-tool .data_table_global_toolbar .layui-btn {
        height: 22px;
        line-height: 22px;
        padding: 0 5px;
        font-size: 12px;
    }

    #table_container .layui-table-tool .data_table_global_toolbar .layui-btn i {
        font-size: 14px !important;
    }

    #table_container #table-col-hide-ctl {
        cursor: pointer;
        color: #A79D9D;
        font-weight: 600;
        float: right;
    }

    #table_container #data_table_search {
        padding: 10px 0;
    }

    #table_container #data_table_search_btn_area {
        padding-left: 40px;
        width: auto;
    }

    #table_container .search-item-number-container .layui-form-select {
        width: 100px;
        float: left;
    }

    #table_container .search-item-number-container .search-item-number {
        width: calc(100% - 120px);
        float: left;
    }

    #table_container .search-item-number-container .search-item-number-min {
        width: calc(50% - 70px);
        float: left;
        border-right: none;
        text-align: center;
        padding-right: 10px;
    }

    #table_container .search-item-number-container .search-item-number-max {
        width: calc(50% - 70px);
        float: left;
        text-align: center;
        border-left: none;
    }

    #table_container .search-item-number-container .search-item-number-to {
        width: 20px;
        float: left;
        text-align: center;
        height: 36px;
        line-height: 36px;
        border-width: 1px;
        border-style: solid;
        background-color: #fff;
        border-color: #e6e6e6;
        border-left: none;
        border-right: none;
    }

    #table_container .search-item-number-container .search-item-number-percent {
        float: left;
        line-height: 38px;
        padding-left: 3px;
    }

    #table_container .layui-icon-help-tip {
        font-size: 11px;
        background: gray;
        border-radius: 50%;
        margin-left: 3px;
        cursor: pointer;
        color: #FFF;
        font-weight: 600;
        padding: 2px 3px;
    }

    #table_container .layui-table-header .layui-table-cell {
        text-overflow: initial;
    }

    #table_container .layui-table-fixed-r {
        display: initial !important;
    }

    #table_container .layui-table-box > .layui-table-header th[data-field="__row__tool__bar__"],
    #table_container .layui-table-box > .layui-table-main td[data-field="__row__tool__bar__"] {
        visibility: hidden;
    }

    #table_container #global_total_row_table {
        margin-bottom: 0px;
        width: 100%;
    }

    #table_container #global_total_row_table td {
        text-align: center;
        background: #ffffff;
        color: #86878A;
        font-weight: 600;
    }
</style>

<!-- 设置表格的行高 -->
<?php 
//这样写是为了防止代码格式化把模版代码格式化乱掉
echo '<'.'style>';
 ?>
#table_container .layui-table-body .layui-table-cell {
height: <?php echo $__table_config['rowHeight']; ?>px;
line-height: <?php echo $__table_config['rowHeight']; ?>px;
}
<?php 
echo '<'.'/style>'
 ?>


<div id="table_container">
    <!-- 表格行工具条 -->
    <div id="data_table_row_toolbar" style="display: none;"></div>

    <!-- 搜索区 -->
    <div id="data_table_search" style="display: none;">
        <form class="layui-form" lay-filter="data_table_search" action="" method="post">
            <div class="layui-row" id="data_table_search_items">
            </div>
            <div class="layui-row">
                <div class="layui-col-xs6" id="data_table_search_btn_area">
                    <button class="layui-btn" lay-submit="" lay-filter="data_table_search_btn">搜索</button>
                    <button type="button" class="layui-btn layui-btn-primary adv-search" style="display: none;">高级搜索
                    </button>
                    <span id="data_table_global_search_toolbar" class="data_table_global_toolbar"></span>
                </div>
            </div>
        </form>
    </div>

    <!-- 全局按钮区 -->
    <div id="data_table_global_top_toolbar" class="data_table_global_toolbar"></div>
    <div id="data_table_global_table_toolbar" style="display: none;">
        <div class="data_table_global_toolbar"></div>
    </div>

    <!-- 自定义区块:表格前面的内容 -->
    
    
    <table class="layui-table" id="global_total_row_table">
        <tr class="title">
        </tr>
        <tr class="value">
        </tr>
    </table>

    <!-- 表格主体 -->
    <table class="layui-hide" id="data_table" lay-filter="data"></table>

    <!-- 自定义区块:表格后面的内容 -->
    
    
</div>

<!-- 表格配置 -->
<?php  $__table_config_json = json_encode($__table_config); ?>
<script>
    var __table_config = <?php echo $__table_config_json; ?>;
    console.log(__table_config);
</script>

<!-- 自定义区块:表格初始化前的前置操作 -->

<script>
    function openUrl(title, url) {
        layer.open({
            type: 2,
            title: title,
            shadeClose: true,
            shade: false,
            maxmin: false,
            area: ['60vw', '80vh'],
            resize: true,
            content: url
        });
    }

    __table_config.fieldsConfig['assets_label'].templet = function (d) {
        var click = 'openUrl(\'' + d.assets_label + '\',\'/<?php echo $moduleName; ?>/admin.assets/log?id=' + d.assets_id + '\')';
        return '<a href="javascript:;" style="text-decoration: underline;" onclick="' + click + '">' + d.assets_label + '</a>';
    };

    __table_config.fieldsConfig['status'].templet = function (d) {
        var c = 'blue';
        if (d.status == '审批通过') {
            c = 'green';
        } else if (d.status == "审批拒绝") {
            c = 'red';
        }
        return '<span class="layui-badge layui-bg-'+c+'">' + d.status + '</span>';
    };
</script>



<script>
    (function ($) {
        //全局对象：表格、表格实例
        var table, tableIns;
        var form;
        var laydate;
        var formSelects;
        var conditions = {};
        var dataUrl = getDataUrl();
        var tableTools = {
            getTableIns: function () {
                return tableIns;
            },
            getConditions: function () {
                return conditions;
            },
            reload: function () {
                g.loading();
                tableIns.reload({
                    url: dataUrl,
                    where: conditions
                });
            },
            reloadRow: function (data, rowObj) {
                console.log(rowObj);
                $.post("row", data, function (ret) {
                    if (ret.code == 1) {
                        rowObj.update(ret.data);
                        if (typeof __table_config.onRowUpdate == 'function') {
                            __table_config.onRowUpdate(tableTools, ret, rowObj);
                        }
                    } else {
                        layer.msg(ret.msg);
                    }
                }, "json");
            },
            getCheckStatus: function () {
                //获取选中行
                var checkStatus = table.checkStatus('data_table');
                return {
                    'data': checkStatus.data,//选中行数据
                    'isAll ': checkStatus.isAll //是否为全选
                };
            },
            getData: function () {
                return table.cache['data_table'];
            }
        };
        __table_config.tableTools = tableTools;

        /**
         * 数据请求地址
         */
        function getDataUrl() {
            var dataUrl = 'data?_=' + (new Date().getTime());
            var query = window.location.search.substring(1);
            var vars = query.split("&");
            var ps = ["___currPage", "___pageSize", "___order", "___where"];
            for (var i = 0; i < vars.length; i++) {
                var pair = vars[i].split("=");
                if (ps.indexOf(pair[0].toLowerCase()) == -1) {
                    dataUrl += "&" + pair[0] + "=" + pair[1];
                }
            }
            return dataUrl;
        }

        /**
         * 表格渲染之前的页面元素初始化
         */
        function initUIBeforeTableRender() {
            // 表格行工具条按钮初始化
            for (var name in __table_config.rowBtns) {
                var rowBtn = __table_config.rowBtns[name];
                var content = rowBtn.title ? rowBtn.title : "";
                if (typeof rowBtn.tip == 'undefined') {
                    rowBtn.tip = rowBtn.title;
                }
                if (rowBtn.icon) {
                    var iconClass = "layui-icon";
                    if (rowBtn.icon.indexOf("ext-") === 0) {
                        iconClass = "layui-icon-ext";
                    }
                    content = '<i class="' + iconClass + ' layui-icon-' + rowBtn.icon + '"></i>' + content;
                }
                var htm = '<a class="layui-btn layui-btn-xs ' + rowBtn.class + '" lay-event="' + name + '" title="' + rowBtn.tip + '">' + content + '</a>';
                $("#data_table_row_toolbar").append(htm);
            }
            // 初始化全局按钮
            var topGlobalHtm = "";
            var searchGlobalHtm = "";
            var tableGlobalHtm = "";
            for (var name in __table_config.globalBtns) {
                var globalBtn = __table_config.globalBtns[name];
                var content = globalBtn.title;
                if (typeof globalBtn.tip == 'undefined') {
                    globalBtn.tip = globalBtn.title;
                }
                if (globalBtn.icon) {
                    content = '<i class="layui-icon layui-icon-' + globalBtn.icon + '"></i>' + content;
                }
                var htm = '<a class="layui-btn ' + globalBtn.class + '" data-event="' + name + '" title="' + globalBtn.tip + '">' + content + '</a>';
                if (globalBtn.position == 'search') {
                    searchGlobalHtm += htm;
                } else if (globalBtn.position == 'top') {
                    topGlobalHtm += htm;
                } else {
                    tableGlobalHtm += htm;
                }
            }
            $("#data_table_global_top_toolbar").append(topGlobalHtm);
            $("#data_table_global_search_toolbar").append(searchGlobalHtm);
            $("#data_table_global_table_toolbar .data_table_global_toolbar").append(tableGlobalHtm);

            // 初始化搜索区域
            initSearchForm();

            // 初始化全局汇总区
            initGlobalTotalRow();
        }

        /**
         * 初始化全局汇总区域
         */
        function initGlobalTotalRow() {
            if (!__table_config.globalTotalRow || __table_config.globalTotalRow.length == 0) {
                $("#global_total_row_table").hide();
                return;
            }
            for (var field in __table_config.globalTotalRow) {
                var globalTotalRowItem = __table_config.globalTotalRow[field];
                if (typeof globalTotalRowItem == 'undefined' || !globalTotalRowItem) {
                    continue;
                }
                if (typeof globalTotalRowItem == 'boolean') {
                    globalTotalRowItem = {};
                }
                globalTotalRowItem = $.extend({
                    title: field,
                    tip: "",
                    unit: ""
                }, globalTotalRowItem);

                var trHtml = "<td class='" + field + "' title='" + globalTotalRowItem.tip + "'>" + globalTotalRowItem.title + "</td>";
                $("#global_total_row_table tr.title").append(trHtml);

                var tdHtml = "<td class='" + field + "' unit='" + globalTotalRowItem.unit + "'></td>"
                $("#global_total_row_table tr.value").append(tdHtml);
            }
        }

        /**
         * 初始化搜索区域
         */
        function initSearchForm() {
            var search = false;
            var adv = false;
            for (var field in __table_config.fieldsConfig) {
                var fieldConfig = __table_config.fieldsConfig[field];
                if (typeof fieldConfig.search == 'undefined' || !fieldConfig.search) {
                    continue;
                }
                var searchFieldConfig = fieldConfig.search;
                if (typeof searchFieldConfig == 'boolean') {
                    searchFieldConfig = {};
                }
                searchFieldConfig = $.extend({
                    type: 'text',
                    width: [6, 6, 4, 3],
                    tip: '',
                    adv: false
                }, searchFieldConfig);
                if (searchFieldConfig.tip == '') {
                    searchFieldConfig.tip = (searchFieldConfig.type == 'select' ? '请选择' : '请输入') + fieldConfig.title;
                }
                if (typeof searchFieldConfig.width != 'object') {
                    searchFieldConfig.width = [searchFieldConfig.width];
                }

                // 生成元素
                var style = (searchFieldConfig.adv ? 'style="display:none;"' : '');
                var className = (searchFieldConfig.adv ? ' layui-form-item-adv' : '');
                var widthClassName = "";
                if (searchFieldConfig.width.length >= 1) {
                    widthClassName += ' layui-col-xs' + searchFieldConfig.width[0];
                }
                if (searchFieldConfig.width.length >= 2) {
                    widthClassName += ' layui-col-sm' + searchFieldConfig.width[1];
                }
                if (searchFieldConfig.width.length >= 3) {
                    widthClassName += ' layui-col-md' + searchFieldConfig.width[2];
                }
                if (searchFieldConfig.width.length >= 4) {
                    widthClassName += ' layui-col-lg' + searchFieldConfig.width[3];
                }
                var htm = "";
                htm += '<div class="' + widthClassName + '">';
                htm += '    <div class="layui-form-item search-item-container ' + className + '" ' + style + ' data-field="' + field + '" data-type="' + searchFieldConfig.type + '">';
                htm += '        <label class="layui-form-label">' + fieldConfig.title + '</label>';
                htm += '        <div class="layui-input-block">';
                switch (searchFieldConfig.type) {
                    case 'select':
                        if (searchFieldConfig.multi) {
                            htm += '<select name="' + field + '" xm-select-search xm-select="search-xm-select-' + field + '" class="search-item xm-select">';
                        } else {
                            htm += '<select name="' + field + '" lay-search class="search-item">';
                        }
                        htm += '<option value="">' + searchFieldConfig.tip + '</option>';
                        var isOptionsArray = searchFieldConfig.options instanceof Array;
                        for (var idx in searchFieldConfig.options) {
                            var option = searchFieldConfig.options[idx];
                            if (option == null) {
                                continue;
                            }
                            if (typeof option != 'object') {
                                option = {
                                    label: option,
                                    val: isOptionsArray ? option : idx
                                };
                            }
                            htm += '<option value="' + option.val + '">' + option.label + '</option>';
                        }
                        htm += '</select>';
                        break;
                    case 'number':
                    case 'percent':
                        htm += '<div class="search-item-number-container" type="' + searchFieldConfig.type + '">';
                        htm += '    <select name="' + field + '_oper___" lay-filter="search-item-number-oper-' + field + '" class="search-item">';
                        htm += '        <option value="eq">等于</option>';
                        htm += '        <option value="gt">大于</option>';
                        htm += '        <option value="egt">大于等于</option>';
                        htm += '        <option value="lt">小于</option>';
                        htm += '        <option value="elt">大于等于</option>';
                        htm += '        <option value="neq">不等于</option>';
                        htm += '        <option value="between" selected>介于</option>';
                        htm += '    </select>';
                        htm += '    <input type="text" name="' + field + '" placeholder="' + searchFieldConfig.tip + '" class="layui-input search-item search-item-number" style="display: none;">';
                        htm += '    <input type="text" name="' + field + '_min___" class="layui-input search-item search-item-number-min">';
                        htm += '    <div class="search-item-number-to"> ~ </div>';
                        htm += '    <input type="text" name="' + field + '_max___" class="layui-input search-item search-item-number-max">';
                        if (searchFieldConfig.type == 'percent') {
                            htm += '<div class="search-item-number-percent">%</div>';
                        }
                        htm += '</div>';
                        break;
                    case 'date':
                    case 'datetime':
                    case 'timestamp':
                    case 'year':
                    case 'month':
                    case 'time':
                        var dateElemType = searchFieldConfig.type;
                        if (dateElemType == 'timestamp') {
                            dateElemType = 'datetime';
                        }
                        if (typeof searchFieldConfig.range == 'undefined') {
                            searchFieldConfig.range = false;
                        } else if (searchFieldConfig.range == true || searchFieldConfig.range == 'true') {
                            searchFieldConfig.range = '-';
                        }
                        if (typeof searchFieldConfig.format == 'undefined') {
                            if (searchFieldConfig.type == 'time') {
                                searchFieldConfig.format = 'HH:mm:ss';
                            } else if (searchFieldConfig.type == 'year') {
                                searchFieldConfig.format = 'yyyy';
                            } else if (searchFieldConfig.type == 'month') {
                                searchFieldConfig.format = 'yyyy-MM';
                            } else if (searchFieldConfig.type == 'date') {
                                searchFieldConfig.format = 'yyyy-MM-dd';
                            } else {
                                //datetime、timestamp
                                searchFieldConfig.format = 'yyyy-MM-dd HH:mm:ss';
                            }
                        }
                        htm += '<input type="text" name="' + field + '" placeholder="' + searchFieldConfig.tip + '" class="layui-input search-item-date search-item" ' +
                            'data-type="' + dateElemType + '" data-range="' + searchFieldConfig.range + '" data-format="' + searchFieldConfig.format + '">';
                        break;
                    case 'text':
                    default:
                        htm += '<input type="text" name="' + field + '" placeholder="' + searchFieldConfig.tip + '" class="layui-input search-item">';
                        break;
                }
                htm += '        </div>';
                htm += '    </div>';
                htm += '</div>';
                $("#data_table_search_items").append(htm);
                search = true;
                adv = adv || searchFieldConfig.adv;
            }
            if (!search) {
                // 没有搜索项，则不需要处理
                return;
            }
            // 渲染搜索表单
            form.render(null, 'data_table_search');

            formSelects.render();

            // 将搜索按钮移动到跟搜索条件同一个区块
            $("#data_table_search_items").append($("#data_table_search_btn_area"));

            // 日期搜索控件初始化
            $("#data_table_search .search-item-date").each(function () {
                var op = {
                    elem: this
                };
                op.type = $(this).attr("data-type");
                op.range = $(this).attr("data-range");
                op.format = $(this).attr("data-format");
                if (op.range === 'false') {
                    op.range = false;
                }
                laydate.render(op);
            });

            // 数值控件初始化
            $("#data_table_search .search-item-number-container select").each(function () {
                form.on('select(' + $(this).attr("lay-filter") + ')', function (data) {
                    if (data.value == 'between') {
                        $(data.elem).parent().find(".search-item-number").hide();
                        $(data.elem).parent().find(".search-item-number-min").show();
                        $(data.elem).parent().find(".search-item-number-max").show();
                        $(data.elem).parent().find(".search-item-number-to").show();
                    } else {
                        $(data.elem).parent().find(".search-item-number").show();
                        $(data.elem).parent().find(".search-item-number-min").hide();
                        $(data.elem).parent().find(".search-item-number-max").hide();
                        $(data.elem).parent().find(".search-item-number-to").hide();
                    }
                });
            });

            //高级搜索
            if (adv) {
                $("#data_table_search .adv-search").show().click(function () {
                    if ($("#data_table_search .layui-form-item-adv").is(":hidden")) {
                        $("#data_table_search .layui-form-item-adv").show();
                        g.resetFormLabel($("#data_table_search form"));
                        $(this).text("简洁搜索");
                    } else {
                        $("#data_table_search .layui-form-item-adv").hide();
                        $(this).text("高级搜索");
                    }
                });
            }

            // 显示搜索区域
            $("#data_table_search").show();
            g.resetFormLabel($("#data_table_search form"));
        }

        /**
         * 表格渲染之后页面元素的初始化
         */
        function initUIAfterTableRender() {
        }

        /**
         * 每次表格数据渲染完成后触发的操作
         */
        function actionAfterTableDataRendered(res, curr, count) {
            g.loading("#global_total_row_table");
            $.post("globalTotalRowData", conditions, function (response) {
                g.loading("#global_total_row_table", false);
                $("#global_total_row_table").show();
                $.each(response.data, function (field, val) {
                    if(val == null) {
                        val = 0;
                    }
                    var $elem = $("#global_total_row_table tr.value ." + field);
                    var unit = $elem.attr("unit");
                    $elem.html(val + (unit || ""));
                });
            }, 'json');

            g.loading(false);
        }

        /**
         * 获取表格配置
         *
         * @returns {{elem: string}}
         */
        function getTableConfig() {
            var tableConfig = {
                elem: '#data_table'
            };

            // 处理表头配置
            var cols = [];
            var leftFixedCols = [];
            var centerCols = [];
            var rightFixedCols = [];
            // 复选框
            if (__table_config.rowCheckbox) {
                leftFixedCols.push({type: 'checkbox', fixed: 'left'});
            }
            // 单选框
            if (__table_config.rowRadio) {
                leftFixedCols.push({type: 'radio', fixed: 'left'});
            }
            // 序号
            if (__table_config.rowNumbers) {
                leftFixedCols.push({type: 'numbers', fixed: 'left'});
            }

            // 处理每个字段列
            for (var field in __table_config.fieldsConfig) {
                var fieldConfig = __table_config.fieldsConfig[field];
                if (!fieldConfig.field) {
                    // 列对应的字段名
                    fieldConfig.field = field;
                }
                if (typeof fieldConfig.title == 'undefined' || !fieldConfig.title) {
                    fieldConfig.title = fieldConfig.field;
                }
                if (typeof fieldConfig.tip != 'undefined' && fieldConfig.tip) {
                    fieldConfig.title += "<i class='layui-icon layui-icon-help layui-icon-help-tip' title='" + fieldConfig.tip + "'></i>";
                }

                //列自定义显示
                if (!fieldConfig.templet) {
                    if (fieldConfig.type == 'number') {
                        //数字
                        fieldConfig.templet = function (d) {
                            if (this.decimalPlaces) {
                                return d[this.field].toFixed(this.decimalPlaces);
                            }
                            return d[this.field];
                        }
                    } else if (fieldConfig.type == 'percent') {
                        //百分比
                        fieldConfig.templet = function (d) {
                            if (this.decimalPlaces) {
                                return (d[this.field] * 100).toFixed(this.decimalPlaces);
                            }
                            return parseInt(d[this.field] * 10000) / 100 + "%";
                        }
                    } else if (fieldConfig.type == 'image') {
                        //图片字段
                        fieldConfig.templet = function (d) {
                            return '<img class="cell-img" src="' + d[this.field] + '" style="height: calc(<?php echo $__table_config['rowHeight']; ?>px - 10px);"/>';
                        }
                    } else if (fieldConfig.type == 'timestamp') {
                        if (typeof fieldConfig.format == 'undefined') {
                            fieldConfig.format = 'yyyy-MM-dd HH:mm:ss';
                        }
                        //时间戳字段
                        fieldConfig.templet = function (d) {
                            if (!d[this.field] || d[this.field] == 0) {
                                return "";
                            }
                            var dt = new Date(d[this.field] * 1000);
                            return dt.toString(this.format);
                        }
                    } else if (fieldConfig.type == 'cdu') {
                        //cdu组件
                        fieldConfig.templet = function (d) {
                            if (!d[this.field] || d[this.field] == null) {
                                return "";
                            }
                            try {
                                var belong = eval("(" + d[this.field] + ")");
                                var names = [];
                                $.each(belong, function () {
                                    names.push(this.name);
                                });
                                return names.join(", ");
                            } catch (e) {
                                return d[this.field];
                            }
                        }
                    } else if (fieldConfig.type == 'bool') {
                        //bool
                        fieldConfig.templet = function (d) {
                            return d[this.field] ? "是" : "否";
                        }
                    }
                }

                if (fieldConfig.totalRowText) {
                    fieldConfig.totalRowText = fieldConfig.totalRowText == true ? "合计" : fieldConfig.totalRowText;
                }

                if (fieldConfig.ignore) {
                    continue;
                }

                fieldConfig.type = "normal";

                if (fieldConfig.fixed == 'left') {
                    leftFixedCols.push(fieldConfig);
                } else if (fieldConfig.fixed == 'right') {
                    rightFixedCols.push(fieldConfig);
                } else {
                    centerCols.push(fieldConfig);
                }
            }
            cols = leftFixedCols.concat(centerCols).concat(rightFixedCols);

            // 行工具条按钮
            if (JSON.stringify(__table_config.rowBtns) != "{}" && JSON.stringify(__table_config.rowBtns) != "[]") {
                var rowBtnsWidth = 40;
                for (var name in __table_config.rowBtns) {
                    var rowBtn = __table_config.rowBtns[name];
                    if (rowBtn.icon) {
                        rowBtnsWidth += 20;
                    }
                    if (typeof rowBtn.title != 'undefined') {
                        rowBtnsWidth += rowBtn.title.length * 15;
                    }
                    rowBtnsWidth += 15;
                }
                cols.push({
                    field: '__row__tool__bar__',
                    title: '操作',
                    fixed: 'right',
                    align: 'center',
                    toolbar: '#data_table_row_toolbar',
                    width: rowBtnsWidth
                });
            }
            tableConfig.cols = [cols];

            // 表格分页配置
            if (typeof __table_config.page == 'object') {
                tableConfig.page = __table_config.page;
            }

            // 表格顶部工具栏
            tableConfig.toolbar = __table_config.toolbar ? __table_config.toolbar : "#data_table_global_table_toolbar";
            tableConfig.defaultToolbar = __table_config.defaultToolbar ? __table_config.defaultToolbar : ['filter', 'print', 'exports'];

            //是否开启合计
            tableConfig.totalRow = __table_config.totalRow;

            // 表格样式
            tableConfig.skin = 'row';
            tableConfig.even = true;

            // 手动限定表格宽度(如果不手动限制，可能在iframe下面会有问题)
            tableConfig.width = (window.frameElement ? $(window.frameElement).width() : $(window).width());
            tableConfig.height = __table_config.height;

            // 初始排序
            for (var orderField in __table_config.order) {
                tableConfig.initSort = {
                    field: orderField,
                    type: __table_config.order[orderField]
                };
                break;
            }
            var orders = [];
            for (var orderField in __table_config.order) {
                orders.push(orderField + "," + __table_config.order[orderField]);
            }
            conditions['___order'] = orders.join(";");

            // 加载数据的时候，显示加载中
            tableConfig.loading = true;

            // 数据加载相关配置
            // tableConfig.url = "data"; //render之前不要设置url，否则在iframe中显示可能会有问题
            tableConfig.method = "post";
            tableConfig.request = {
                pageName: '___currPage',
                limitName: '___pageSize'
            };
            if (typeof __table_config.onAfterDataLoaded == 'function') {
                //数据获取成功，处理数据
                tableConfig.parseData = function (res) {
                    return __table_config.onAfterDataLoaded(res);
                };
            }
            tableConfig.done = function (res, curr, count) {
                //数据渲染完毕
                actionAfterTableDataRendered(res, curr, count);
                if (typeof __table_config.done == 'function') {
                    __table_config.done(tableTools, res, curr, count);
                }
            };
            console.log(tableConfig);
            return tableConfig;
        }

        /**
         * 全局工具栏的默认操作
         */
        function applyGlobalToolbarDefaultAction(event, checkedRows) {
            if (event == 'refresh') {
                // 表格刷新
                g.loading();
                tableTools.reload();
                return true;
            }
            return false;
        }

        /**
         * 将行数据转换为可读形式
         */
        function getReadableRow(row) {
            var readableRow = {};
            $.each(row, function (key, value) {
                var fieldConfig = __table_config.fieldsConfig[key];
                if (fieldConfig['ignore']) {
                    return;
                }
                var title = fieldConfig['title'];

                if (typeof fieldConfig.templet == 'function') {
                    fieldConfig.templet.call(fieldConfig, row);
                }

                readableRow[title] = value;
            });
            return readableRow;
        }

        /**
         * 将行数据转换为html
         */
        function getReadableRowHtml(row) {
            var html = [];
            row = getReadableRow(row);
            $.each(row, function (key, value) {
                html.push(key + ": " + value);
            });
            return '<blockquote class="layui-elem-quote">' + html.join("<br/>") + '</blockquote>';
        }

        /**
         * 行工具栏的默认操作
         */
        function applyRowToolbarDefaultAction(event, row, rowObj, option) {
            if (event == 'del') {
                var confirmTitle;
                if (!option.ajax || typeof option.ajax.confirm != "string") {
                    confirmTitle = "确认删除该记录？<br/>" + getReadableRowHtml(row);
                } else {
                    confirmTitle = option.ajax.confirm;
                }
                if (row) {
                    for (var param in row) {
                        var val = row[param];
                        confirmTitle = confirmTitle.replace(new RegExp('###__' + param + '__###', 'g'), val);
                    }
                }
                layer.confirm(confirmTitle, {title: "请确认"}, function () {
                    g.loading();
                    $.post("del", row, function (ret) {
                        g.loading(false);
                        if (ret.code == 1) {
                            layer.msg(ret.msg);
                            rowObj.del();
                        } else {
                            layer.alert(ret.msg);
                        }
                    }, 'json');
                });
                return true;
            }
            return false;
        }

        /**
         * 工具条响应操作
         */
        function handleToolbarAction(type, event, option, data, rowObj) {
            var action = option['action'];
            if (!action) {
                // 如果没有指定action，则尝试执行默认的操作
                var defaultActionHandled = false;
                if (type == 'row') {
                    defaultActionHandled = applyRowToolbarDefaultAction(event, data, rowObj, option);
                } else {
                    defaultActionHandled = applyGlobalToolbarDefaultAction(event, data);
                }
                if (defaultActionHandled) {
                    // 如果执行了默认操作，不需要继续向下执行了
                    return;
                }
                // 如果没执行默认操作，则action默认设置为event
                action = event;
            }
            console.log(action);

            if (typeof window[action] == 'function') {
                // 如果对应的action是一个函数，则执行函数
                eval("(" + action + "(" + JSON.stringify(data) + ", rowObj, tableTools))");
            } else {
                // 否则打开新页面、跳转链接等

                // 拼装url
                var row = type == 'row' ? data : (data.length > 0 ? data[0] : false);
                var url = action;
                if (row) {
                    for (var param in row) {
                        var val = row[param];
                        url = url.replace(new RegExp('###__' + param + '__###', 'g'), val);
                    }
                }
                console.log(url);

                if (option.dlg) {
                    // 对话框弹出
                    if (typeof option.dlg != 'object') {
                        option.dlg = {};
                    }
                    if (!option.dlg.width) {
                        option.dlg.width = '60vw';
                    }
                    if (!option.dlg.height) {
                        option.dlg.height = '80vh';
                    }
                    if (!option.dlg.reload) {
                        option.dlg.reload = false;
                    }
                    var dlgTitle = option.dlg.title;
                    if (!dlgTitle) {
                        dlgTitle = option.title || option.tip;
                    }
                    if (row) {
                        for (var param in row) {
                            var val = row[param];
                            dlgTitle = dlgTitle.replace(new RegExp('###__' + param + '__###', 'g'), val);
                        }
                    }
                    layer.open({
                        type: 2,
                        title: dlgTitle,
                        shadeClose: true,
                        shade: 0.8,
                        maxmin: false,
                        area: [option.dlg.width, option.dlg.height],
                        resize: true,
                        content: url,
                        cancel: function (index, layero) {
                            //对话框关闭时执行的操作
                            //如果设置了对话框关闭后刷新，则进行刷新
                            if (option.dlg.reload) {
                                if (typeof rowObj == 'undefined' || option.dlg.reload == 'all') {
                                    tableTools.reload();
                                } else {
                                    tableTools.reloadRow(data, rowObj);
                                }
                            }
                            console.log(layero);

                            try {
                                // 检查iframe内部有没有设置关闭前的检查
                                var iframe = layero.find("iframe")[0];
                                if (iframe && iframe.contentWindow && iframe.contentWindow.actionBeforeWindowClose) {
                                    return iframe.contentWindow.actionBeforeWindowClose(function () {
                                        layer.close(index);
                                    });
                                }
                            } catch (e) {
                                console.error(e);
                            }
                            return true;
                        }
                    });
                } else if (option.tab) {
                    if (window.parent && window.parent.openTab) {
                        window.parent.openTab(false, url);
                    } else {
                        window.location.href = url;
                    }
                } else if (option.ajax) {
                    // ajax加载
                    if (typeof option.ajax != 'object') {
                        option.ajax = {};
                    }
                    if (!option.ajax.type) {
                        option.ajax.type = "get";
                    }
                    if (!option.ajax.reload) {
                        option.ajax.reload = false;
                    }
                    var ajaxOption = {
                        url: url,
                        data: row,
                        type: option.ajax.type,
                        beforeSend: function () {
                            g.loading();
                        },
                        complete: function () {
                            g.loading(false);
                        },
                        error: function (xhr, msg, e) {
                            layer.alert("请求失败：" + msg);
                        },
                        success: function (data) {
                            if (data.code == 1) {
                                layer.msg(data.msg);
                                if (option.ajax.reload) {
                                    if (typeof rowObj == 'undefined' || option.ajax.reload == 'all') {
                                        tableTools.reload();
                                    } else {
                                        tableTools.reloadRow(data, rowObj);
                                    }
                                }
                            } else {
                                layer.alert(data.msg);
                            }
                        }
                    };
                    if (option.ajax.confirm) {
                        var confirmTitle;
                        if (typeof option.ajax.confirm != "string") {
                            confirmTitle = "确认执行该操作？";
                        } else {
                            confirmTitle = option.ajax.confirm;
                        }
                        if (row) {
                            for (var param in row) {
                                var val = row[param];
                                confirmTitle = confirmTitle.replace(new RegExp('###__' + param + '__###', 'g'), val);
                            }
                        }
                        layer.confirm(confirmTitle, {title: "请确认"}, function () {
                            $.ajax(ajaxOption);
                        });
                    } else {
                        $.ajax(ajaxOption);
                    }
                } else {
                    if (option.openBlankWin) {
                        window.open(url);
                    } else {
                        document.location.href = url;
                    }
                }
            }
        }

        /**
         * 表格渲染完毕后，初始化相关事件
         */
        function initEventAfterTableRender() {
            // 响应排序操作
            table.on('sort(data)', function (obj) {
                conditions['___order'] = obj.field + "," + obj.type;
                table.reload('data_table', {
                    initSort: obj
                    , where: conditions
                });
            });

            // 响应行工具条按钮
            table.on('tool(data)', function (rowObj) {
                var row = rowObj.data;
                console.log(row);
                var rowBtn = __table_config.rowBtns[rowObj.event];
                if (!rowBtn) {
                    return;
                }
                handleToolbarAction('row', rowObj.event, rowBtn, row, rowObj);
            });

            //响应顶部全局工具条
            $("body").delegate(".data_table_global_toolbar .layui-btn", 'click', function () {
                var event = $(this).attr("data-event");
                var globalBtn = __table_config.globalBtns[event];
                if (!globalBtn) {
                    return;
                }
                var checkedRows = table.checkStatus('data_table').data;
                handleToolbarAction('global', event, globalBtn, checkedRows);
            });

            // 行内图片点击
            $("body").delegate("img.cell-img", "click", function () {
                var src = $(this).attr("src");
                layer.photos({
                    photos: {
                        "data": [{
                            "src": src,
                            "thumb": src
                        }]
                    }
                });
            });

            // 搜索事件
            form.on('submit(data_table_search_btn)', function (data) {
                console.dir(data);
                var fieldValues = data.field;

                //多选框
                $("#data_table_search_items select.xm-select").each(function () {
                    var xmId = $(this).attr("xm-select");
                    var field = xmId.replace("search-xm-select-", "");
                    var val = formSelects.value(xmId, 'val');
                    fieldValues[field] = val;
                });

                try {
                    search(fieldValues);
                } catch (e) {
                    console.error(e);
                } finally {
                    return false;
                }
            });
        }

        /**
         * 搜索
         *
         * @param fieldValues
         */
        function search(fieldValues) {
            var wheres = {};
            $("#data_table_search .search-item-container").each(function () {
                var field = $(this).attr('data-field');
                var fieldConfig = __table_config.fieldsConfig[field];
                var type = $(this).attr('data-type');
                var val = fieldValues[field] || '';
                var where = {};
                switch (type) {
                    case 'select':
                        if ($(this).find(".search-item").hasClass("xm-select")) {
                            //多选
                            where.oper = 'in';
                            where.val = val;
                        } else {
                            where.oper = 'eq';
                            where.val = val;
                        }
                        break;
                    case 'number':
                    case 'percent':
                        var oper = fieldValues[field + "_oper___"];
                        if (oper == 'between') {
                            var min = fieldValues[field + "_min___"];
                            var max = fieldValues[field + "_max___"];
                            if (min && max) {
                                val = [min, max];
                            } else if (min) {
                                oper = "egt";
                                val = min;
                            } else if (max) {
                                oper = "elt";
                                val = max;
                            } else {
                                val = "";
                            }
                        }
                        where.oper = oper;
                        where.val = val;
                        if (type == 'percent') {
                            if (oper == 'between') {
                                where.val[0] = where.val[0] / 100;
                                where.val[1] = where.val[1] / 100;
                            } else if (where.val) {
                                where.val = where.val / 100;
                            }
                        }
                        break;
                    case 'date':
                    case 'datetime':
                    case 'timestamp':
                    case 'year':
                    case 'month':
                    case 'time':
                        var range = $(this).find(".search-item-date").attr('data-range');
                        var format = $(this).find(".search-item-date").attr('data-format');
                        if (range && range != "false") {
                            val = val ? val.split(" " + range + " ") : [];
                            where.oper = 'between';
                        } else {
                            where.oper = 'eq';
                        }
                        if (type == 'timestamp') {
                            // 转换成时间戳
                            if (val == [] || val == '') {
                                // 没有值，不处理
                            } else if (typeof val == 'object') {
                                val[0] = Date.parse(val[0]).getTime() / 1000;
                                val[1] = Date.parse(val[1]).getTime() / 1000;
                            } else {
                                val = Date.parse(val).getTime() / 1000;
                            }
                        }
                        where.val = val;
                        where.format = format;
                        break;
                    case 'text':
                    default:
                        where.oper = 'like';
                        where.val = (val ? ('%' + val + '%') : '');
                        break;
                }
                wheres[field] = where;
            });

            conditions['___where'] = JSON.stringify(wheres);
            console.log(conditions);
            g.loading();
            tableIns.reload({
                url: dataUrl,
                where: conditions,
                page: {curr: 1}
            });
        }

        //初始化表格
        layui.use(['table', 'form', 'laydate', 'formSelects'], function () {
            table = layui.table;
            form = layui.form;
            laydate = layui.laydate;
            formSelects = layui.formSelects;

            initTableOnPageLoaded();
        });

        function initTableOnPageLoaded() {
            if ($(window).width() == 0) {
                //如果表格所在的区域，刚开始是隐藏的，则获取不到窗口宽度，这边就等待
                setTimeout(function () {
                    initTableOnPageLoaded();
                }, 500);
                return;
            }

            // 表格初始化之前，首先初始化一下相关页面元素
            initUIBeforeTableRender();

            // 获取表格配置
            var tableConfig = getTableConfig();
            console.dir(tableConfig);

            // 渲染表格
            tableIns = table.render(tableConfig);

            // 表格渲染完毕，初始化相关页面元素
            initUIAfterTableRender();

            // 表格渲染完毕，初始化相关事件
            initEventAfterTableRender();

            // 加载数据（加载数据不要跟render一起，否则在iframe的时候，可能会显示有问题）
            g.loading();
            table.reload('data_table', {
                url: dataUrl,
                where: conditions
            });
        }

    })(jQuery);
</script>

<!-- 自定义区块:表格初始化前的后置操作 -->




<?php 
if(isset($_enterprise_js_css_customize)) {
echo $_enterprise_js_css_customize;
}
 ?>
</body>
</html>